chai = require 'chai'
chai.should()
sinon = require 'sinon'
should = require 'should'
{MemoryRepository} = require '../src/memoryRepository'

describe 'MemoryRepository Instance with object value', ->

  myObjectValue = {name: 'My name', message: 'My message.'}
  myOtherObjectValue = {name: 'My other name', message: 'My other message.'}

  it 'should instantiate', ->
    repo = new MemoryRepository()
    repo.should.not.be.null

  it 'should store value', (done)->
    repo = new MemoryRepository()
    repo.set 'MyKey', myObjectValue, (err) ->
      repo.get 'MyKey', (err, value) ->
        value.should.equal myObjectValue
        value.should.not.equal myOtherObjectValue
        done()

  it 'should remove stored value', (done) ->
    repo = new MemoryRepository()
    repo.set 'MyKey', myObjectValue, (err)->
      repo.get 'MyKey', (err, value)->
        value.should.equal myObjectValue
        repo.remove 'MyKey', (err) ->
          should.not.exist err
          repo.get 'MyKey', (err, value)->
            should.not.exist value
            done()

  it 'should return true for contained value', (done)->
    repo = new MemoryRepository()
    repo.set 'MyKey', myObjectValue, ()->
      repo.contains 'MyKey', (err, isContained) ->
        isContained.should.be.true
        done()


